package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Employee;
import service.Service;

/**
 * Servlet implementation class SetPunishParamServlet
 */
@WebServlet("/SetPunishParamServlet")
public class SetPunishParamServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SetPunishParamServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		int empId = Integer.parseInt(request.getParameter("empId"));
		double leaveParam = Double.parseDouble(request.getParameter("leaveParam"));
		double lateParam = Double.parseDouble(request.getParameter("lateParam"));
		double absentParam = Double.parseDouble(request.getParameter("absentParam"));
		double overtimeParam = Double.parseDouble(request.getParameter("overtimeParam"));
		Employee emp = new Employee();
		Service s = new Service();
		emp.setId(empId);
		emp.setLeaveParam(leaveParam);
		emp.setLateParam(lateParam);
		emp.setAbsentParam(absentParam);
		emp.setOvertimeParam(overtimeParam);
		if(s.setPunishParam(emp)) {
			request.getRequestDispatcher("a_other/success.jsp").forward(request, response);
		}
	}

}
